package com.jsbj.user.controller;


import com.jsbj.base.ResultBean;
import com.jsbj.framework.controller.BaseController;
import com.jsbj.page.PageReq;
import com.jsbj.user.entities.SysNotice;
import com.jsbj.user.service.ISysNoticeService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 通知表 前端控制器
 * </p>
 *
 * @author jsbj
 * @since 2023-05-11
 */
@RestController
@Api(value = "通知管理", tags = "通知管理")
@RequestMapping("/sys-notice")
public class SysNoticeController extends BaseController {

    @Autowired
    private ISysNoticeService sysNoticeService;

    @ApiOperation("分页列表")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "String", name = "userId", value = "用户登录id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "page", value = "页码", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "pageSize", value = "每页条数", required = true)}
    )
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功", response = SysNotice.class)})
    @PostMapping("/pageList")
    public ResultBean<PageReq> pageList(@RequestBody String inParam) {
        return new ResultBean<PageReq>(getPage(sysNoticeService.pageList(inParam)));
    }

    @ApiOperation("新增")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "String", name = "userId", value = "用户登录id", required = true)}
    )
    @PostMapping(value = "add")
    public ResultBean<Boolean> add(@RequestBody SysNotice sysNotice) {

        return new ResultBean<>(sysNoticeService.add(sysNotice));
    }

    @ApiOperation("编辑")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "String", name = "userId", value = "用户登录id", required = true)}
    )
    @PostMapping(value = "update")
    public ResultBean<Boolean> update(@RequestBody SysNotice sysNotice)  {

        return new ResultBean<>(sysNoticeService.update(sysNotice));
    }

    @ApiOperation("详情")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "String", name = "userId", value = "用户登录id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "id", value = "数据id", required = true)}
    )
    @GetMapping(value = "detail")
    public ResultBean<SysNotice> detail(@RequestParam String id) {

        return new ResultBean<>(sysNoticeService.detail(id));
    }

    @ApiOperation("删除")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "String", name = "userId", value = "用户登录id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "id", value = "数据id", required = true)}
    )
    @GetMapping(value = "delete")
    public ResultBean<Boolean> delete(@RequestParam String id) {

        return new ResultBean<>(sysNoticeService.delete(id));
    }

    @ApiOperation("发布")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "String", name = "userId", value = "用户登录id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "id", value = "数据id", required = true)}
    )
    @GetMapping(value = "publish")
    public ResultBean<Boolean> publish(@RequestParam String id) {

        return new ResultBean<>(sysNoticeService.publish(id));
    }


}

